<?php

/* 
 * Copyright (C) 2014 vlasta81
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */


if (DEVELOP === FALSE) : error_reporting(0);
else : error_reporting(E_ALL);
endif;

function exceptionHandler(Exception $e) {
    if (DEVELOP === FALSE) :
        echo '<strong>NASTALA CHYBA! Kontaktujte správce. </strong>' . date('j. n. Y - G:i') . '<br>';
        error_log("---VYJÍMKA---\n", 3, "./errorsException.log");
        error_log("čas: " . date('j. n. Y - G:i') . "\n", 3, "./errorsException.log");
        error_log("zpráva: " . $e->getMessage() . "\n", 3, "./errorsException.log");
        error_log("vyjímka ze souboru: " . $e->getFile() . "\n", 3, "./errorsException.log");
        error_log("řádek: " . $e->getLine() . "\n", 3, "./errorsException.log");
        error_log("kód: " . $e->getCode() . "\n", 3, "./errorsException.log");
        error_log("\n*********************************\n", 3, "./errorsException.log");
        exit();
    else:
        echo '<strong>NASTALA VYJÍMKA:</strong><br>';
        echo '<strong>čas:</strong> ' . date('j. n. Y - G:i') . '<br>';
        echo '<strong>zpráva:</strong> ' . $e->getMessage() . '<br>';
        echo '<strong>vyjímka ze souboru:</strong> ' . $e->getFile() . '<br>';
        echo '<strong>řádek:</strong> ' . $e->getLine() . '<br>';
        echo '<strong>kód chyby:</strong> ' . $e->getCode() . '<br><br>';
        exit();
    endif;
} set_exception_handler('exceptionHandler');

function errorHandler($errno, $errstr, $errfile, $errline) {
    if (DEVELOP === FALSE) :
        echo '<strong>NASTALA CHYBA! Kontaktujte správce. </strong>' . date('j. n. Y - G:i') . '<br>';
        error_log("---CHYBA---\n", 3, "./errors.log");
        error_log("čas: " . date('j. n. Y - G:i') . "\n", 3, "./errors.log");
        error_log("zpráva: " . $errstr . "\n", 3, "./errors.log");
        error_log("chyba ze souboru: " . $errfile . "\n", 3, "./errors.log");
        error_log("řádek: " . $errline . "\n", 3, "./errors.log");
        error_log("kód: " . $errno . "\n", 3, "./errors.log");
        error_log("\n*********************************\n", 3, "./errors.log");
        return;
    else:
        echo '<strong>NASTALA CHYBA:</strong><br>';
        echo '<strong>čas:</strong> '. date('j. n. Y - G:i')."<br>";
        echo '<strong>zpráva:</strong> '. $errstr."<br>";
        echo '<strong>chyba ze souboru:</strong> '. $errfile."<br>";
        echo '<strong>řádek:</strong> '. $errline."<br>";
        echo '<strong>kód chyby:</strong> '. $errno."<br><br>";
        return;
    endif;
} set_error_handler('errorHandler');
